import FSMManager from "./FSMManager";
import attack1 from "./state/attack1";
import attack2 from "./state/attack2";
import attack3 from "./state/attack3";
import runState from "./state/runState";
import standState from "./state/standState";

const {ccclass, property} = cc._decorator;

// 创建状态枚举
enum PersonState {
    stand = 0,
    run,
    attack1,
    attack2,
    attack3
}

let stateClassArr = [
    standState,
    runState,
    attack1,
    attack2,
    attack3
]

@ccclass
export default class personControl extends cc.Component {
    // 动画
    ani: cc.Animation;
    // 状态机
    fsmManager: FSMManager;

    // onLoad () {}

    start () {
        this.ani = this.node.getComponent(cc.Animation);
        this.fsmManager = new FSMManager();
        // 创建几个动作状态
        for(let i in PersonState) {
            let index = Number(i);
            if (!isNaN(index)) {
                this.fsmManager.stateList.push(new stateClassArr[index](index, this, this.fsmManager));
            }
        }
        // console.log(this.fsmManager.stateList);
        // 开始执行状态
        // this.stand();
    }

    // 站立
    stand() {
        this.fsmManager.changeState(PersonState.stand);
    }
    // 跑步
    run() {
        this.fsmManager.changeState(PersonState.run);
    }
    // 攻击
    attack1() {
        this.fsmManager.changeState(PersonState.attack1);
    }
    attack2() {
        this.fsmManager.changeState(PersonState.attack2);
    }
    attack3() {
        this.fsmManager.changeState(PersonState.attack3);
    }



    update (dt) {

    }
}
